//new calibration of marriage probabilities that factors spousal education into account
//function: linear function of age, estimated separately by education and race. 


use "$temp/psid_estimation_sample", clear
sort uniqid year

//next-period marriage, fertility
gen mp = m[_n+1] if uniqid[_n] == uniqid[_n+1]

//next-period marriage
gen married_p = (mp>1)
replace married_p = . if mp == .
gen married = (m>1) //currently married


//recoding some more stuff
replace e = e-1
replace e_sp = e_sp - 1
replace e_sp = . if e_sp == -1
replace age = age + 21

//ALL
preserve
su e_sp if e == 0
local e_sp_1 = `r(mean)'

su e_sp if e == 1
local e_sp_2 = `r(mean)'

collapse (mean) married_p, by(age married e)

reg married_p age if e==0 & married == 0
local m0 = _b[_cons]
local mb0 = _b[age] + 0.001

reg married_p age if e==1 & married == 0
local m1 = _b[_cons] 
local mb1 = _b[age] + 0.002

su married_p if e==0 & married //divorce rate
local div_0 `r(mean)'
su married_p if e==1 & married //divorce rate
local div_1 `r(mean)'

//probabiliyt of low-type match; calibrated from data previously
clear
set obs 3
gen v1 = 0
gen v2 = 0
gen v3 = 0
gen v4 = 0

replace v1 = `e_sp_1' in 1
replace v2 = `m0' in 1
replace v3 = `mb0' in 1
replace v4 = `div_0' in 1

replace v1 = `e_sp_2' in 2
replace v2 = `m1' in 2
replace v3 = `mb1' in 2
replace v4 = `div_1' in 2


replace v1 = 0.5979 in 3
export delimited "$model/utilities/trans_probs_v2.csv", replace novarn
restore


//WHITES
preserve
keep if race == 1
su e_sp if e == 0
local e_sp_1 = `r(mean)'

su e_sp if e == 1
local e_sp_2 = `r(mean)'

collapse (mean) married_p, by(age married e)

reg married_p age if e==0 & married == 0
local m0 = _b[_cons]
local mb0 = _b[age] + 0.001

reg married_p age if e==1 & married == 0
local m1 = _b[_cons]
local mb1 = _b[age] + 0.002

su married_p if e==0 & married //divorce rate
local div_0 `r(mean)'
su married_p if e==1 & married //divorce rate
local div_1 `r(mean)'

clear
set obs 3
gen v1 = 0
gen v2 = 0
gen v3 = 0
gen v4 = 0

replace v1 = `e_sp_1' in 1
replace v2 = `m0' in 1
replace v3 = `mb0' in 1
replace v4 = `div_0' in 1

replace v1 = `e_sp_2' in 2
replace v2 = `m1' in 2
replace v3 = `mb1' in 2
replace v4 = `div_1' in 2


//probabiliyt of low-type match; calibrated from data previously
replace v1 = 0.5429 in 3
export delimited "$model/utilities/trans_probs_whites_v2.csv", replace novarn



restore





//BLACKS
preserve
keep if race == 2
su e_sp if e == 0
local e_sp_1 = `r(mean)'

su e_sp if e == 1
local e_sp_2 = `r(mean)'

collapse (mean) married_p, by(age married e)

reg married_p age if e==0 & married == 0
local m0 = _b[_cons]
local mb0 = _b[age] + 0.0005

reg married_p age if e==1 & married == 0
local m1 = _b[_cons]
local mb1 = _b[age] + 0.0005

su married_p if e==0 & married //divorce rate
local div_0 `r(mean)'
su married_p if e==1 & married //divorce rate
local div_1 `r(mean)'

clear
set obs 3
gen v1 = 0
gen v2 = 0
gen v3 = 0
gen v4 = 0

replace v1 = `e_sp_1' in 1
replace v2 = `m0' in 1
replace v3 = `mb0' in 1
replace v4 = `div_0' in 1

replace v1 = `e_sp_2' in 2
replace v2 = `m1' in 2
replace v3 = `mb1' in 2
replace v4 = `div_1' in 2

//probabiliyt of low-type match; calibrated from data previously
replace v1 = 0.7407 in 3
export delimited "$model/utilities/trans_probs_blacks_v2.csv", replace novarn

restore


